﻿Public Class TZPage
    Friend WithEvents currentApppointment As Outlook.AppointmentItem
    Shared WithEvents cApp As Outlook.AppointmentItem
#Region "Form Region Factory"

    <Microsoft.Office.Tools.Outlook.FormRegionMessageClass(Microsoft.Office.Tools.Outlook.FormRegionMessageClassAttribute.Appointment)> _
    <Microsoft.Office.Tools.Outlook.FormRegionName("Outlook2007DIT.TZPage")> _
    Partial Public Class TZPageFactory

    ' Occurs before the form region is initialized.
    ' To prevent the form region from appearing, set e.Cancel to true.
    ' Use e.OutlookItem to get a reference to the current Outlook item.
        Private Sub TZPageFactory_FormRegionInitializing(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs) Handles Me.FormRegionInitializing
            cApp = e.OutlookItem
    End Sub

    End Class

#End Region

    'Occurs before the form region is displayed. 
    'Use Me.OutlookItem to get a reference to the current Outlook item.
    'Use Me.OutlookFormRegion to get a reference to the form region.
    Private Sub TZPage_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing
        Me.currentApppointment = cApp
     
        Dim formRegions As WindowFormRegionCollection = Globals.FormRegions(Globals.ThisAddIn.Application.ActiveInspector())
        Dim tzs As System.Collections.Hashtable
        tzs = GetAppointTimeZones()

        Dim f As New TZMatrix(tzs)
        Me.Controls.Add(f)
        f.Dock = Windows.Forms.DockStyle.Fill



    End Sub

    'Occurs when the form region is closed.   
    'Use Me.OutlookItem to get a reference to the current Outlook item.
    'Use Me.OutlookFormRegion to get a reference to the form region.
    Private Sub TZPage_FormRegionClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionClosed

    End Sub

    Function GetAppointTimeZones() As System.Collections.Hashtable
        Dim a As New System.Collections.Hashtable
        Dim formRegions As WindowFormRegionCollection = Globals.FormRegions(Globals.ThisAddIn.Application.ActiveInspector())
        a.Add(cApp.StartTimeZone.ID, cApp.StartTimeZone.Name)

        With formRegions.InternationalTimes.dgvTimes
            For i = 0 To .Rows.Count - 1

                a.Add(.Rows(i).Cells("dgvTimeZone").Value, .Rows(i).Cells("dgvLocation").Value)

            Next
        End With
        GetAppointTimeZones = a


    End Function
End Class
